package com.xindong.paking.controller;


import com.xindong.paking.dtos.TbBalanceListParams;
import com.xindong.paking.entity.TbBalance;
import com.xindong.paking.service.TbBalanceService;
import com.xindong.paking.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wenbo
 * @since 2023-01-11
 */
@Api(tags = "余额模块")
@RestController
@RequestMapping("/tb-balance")
public class TbBalanceController {

    @Autowired
    private TbBalanceService tbBalanceService;

    /**
     * 增加余额
     * @param tbBalance
     * @return
     */
    @ApiOperation("新增余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    })
    @PostMapping("add")
    public Result add(@RequestBody TbBalance tbBalance) {
        return tbBalanceService.add(tbBalance);
    }

    /**
     * 删除余额
     * @param id
     * @return
     */
    @ApiOperation("删除余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对应余额id", required = true)
    })
    @DeleteMapping("delete")
    public Result delete(@RequestParam("id") Integer id) {
        return tbBalanceService.delete(id);
    }

    /**
     * 更新余额
     * @param tbBalance
     * @return
     */
    @ApiOperation("更新余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对应余额id", required = true),
            @ApiImplicitParam(name = "balance", value = "余额"),
            @ApiImplicitParam(name = "integral", value = "积分"),
            @ApiImplicitParam(name = "userId", value = "用户id")
    })
    @PutMapping("update")
    public Result update(@RequestBody TbBalance tbBalance) {
        return tbBalanceService.update(tbBalance);
    }

    /**
     * 分页查询余额
     * @param params
     * @return
     */
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true),
            @ApiImplicitParam(name = "id", value = "对应余额id"),
            @ApiImplicitParam(name = "balance", value = "余额"),
            @ApiImplicitParam(name = "integral", value = "积分"),
            @ApiImplicitParam(name = "userId", value = "用户id")
    })
    @GetMapping("list")
    public Result list(TbBalanceListParams params) {
        return tbBalanceService.list(params);
    }

    /**
     * 余额充值
     * @param money
     * @return
     */
    @ApiOperation("余额充值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money", value = "充值金额", required = true)
    })
    @PutMapping("recharge")
    public Result recharge(Double money) {
        return tbBalanceService.recharge(money);
    }

    /**
     * 余额扣款
     * @param money
     * @return
     */
    @ApiOperation("余额扣款")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money", value = "扣款金额", required = true)
    })
    @PutMapping("deduction")
    public Result deduction(Double money) {
        return tbBalanceService.deduction(money);
    }

    /**
     * 积分增加
     * @param integral
     * @return
     */
    @ApiOperation("积分增加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "integral", value = "增加积分", required = true)
    })
    @PutMapping("pointsIncrease")
    public Result pointsIncrease(Integer integral) {
        return tbBalanceService.pointsIncrease(integral);
    }

    /**
     * 积分兑换
     * @param integral
     * @return
     */
    @ApiOperation("积分兑换")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "integral", value = "扣除积分", required = true)
    })
    @PutMapping("pointsRedemption")
    public Result pointsRedemption(Integer integral) {
        return tbBalanceService.pointsRedemption(integral);
    }

    /**
     * 根据id查询用户余额
     * @param userId
     * @return
     */
    @ApiOperation("根据id查询用户余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    })
    @GetMapping("selectMoneyByUserId")
    public Result selectMoneyByUserId(Integer userId) {
        return tbBalanceService.selectMoneyByUserId(userId);
    }

    /**
     * 根据id查询用户积分
     * @param userId
     * @return
     */
    @ApiOperation("根据id查询用户积分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    })
    @GetMapping("selectIntegralByUserId")
    public Result selectIntegralByUserId(Integer userId) {
        return tbBalanceService.selectIntegralByUserId(userId);
    }

    /**
     * 根据id增加余额
     * @param tbBalance
     * @return
     */
    @ApiOperation("根据id增加余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true),
            @ApiImplicitParam(name = "balance", value = "金额", required = true)
    })
    @PutMapping("addMoneyByUserId")
    public Result addMoneyByUserId(@RequestBody TbBalance tbBalance) {
        return tbBalanceService.addMoneyByUserId(tbBalance);
    }

    /**
     * 根据id增加积分
     * @param tbBalance
     * @return
     */
    @ApiOperation("根据id增加积分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true),
            @ApiImplicitParam(name = "integral", value = "积分", required = true)
    })
    @PutMapping("addIntegralByUserId")
    public Result addIntegralByUserId(@RequestBody TbBalance tbBalance) {
        return tbBalanceService.addIntegralByUserId(tbBalance);
    }

}

